home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / Plug-in - WireFrame Renderer / SR_Triangle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  4.2 KB  |  175 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        SR_Triangle.c                                             **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **     Purpose:     Sample Renderer triangle routines                          **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **                                                                          **
  10.  **     Copyright (C) 1996 Apple Computer, Inc.  All rights reserved.          **
  11.  **                                                                          **
  12.  **                                                                          **
  13.  *****************************************************************************/
  14. #include <assert.h>
  15.  
  16. #include "QD3D.h"
  17.  
  18. #include "SR.h"
  19. #include "SR_Math.h"
  20.  
  21.  
  22. /*===========================================================================*\
  23.  *
  24.  *    Routine:    SR_Geometry_Triangle()
  25.  *
  26.  *    Comments:    
  27.  *
  28. \*===========================================================================*/
  29.  
  30. TQ3Status SR_Geometry_Triangle(
  31.     TQ3ViewObject             view, 
  32.     TSRPrivate                 *srPrivate,
  33.     TQ3GeometryObject         triangle, 
  34.     const TQ3TriangleData    *triangleData)
  35. {
  36.     unsigned long            numVertices;
  37.     TQ3Boolean                highlightState;
  38.     TQ3XClipMaskState        clipMaskState;
  39.     TQ3ColorRGB                color;
  40.     TQ3Vector3D                normal;
  41.     
  42.     UNUSED(triangle);
  43.  
  44.     assert(view            != NULL);
  45.     assert(srPrivate    != NULL);
  46.     assert(triangleData    != NULL);
  47.  
  48.     /*
  49.      *  Call the application's idle progress method, via the view.  If
  50.      *  the app's method returns kQ3Failure, then we don't go on.
  51.      */
  52.     if (SR_IdleProgress(view, srPrivate) == kQ3Failure) {
  53.         return (kQ3Success);
  54.     }
  55.  
  56.     if (srPrivate->drawRegion == NULL) {
  57.         return (kQ3Success);
  58.     }
  59.     
  60.     /*
  61.      *  Find out if we're clipped out or not. No reason to go any
  62.      *  further if the region is obscured or entirely off-screen. 
  63.      */
  64.     Q3XDrawRegion_GetClipFlags(srPrivate->drawRegion, &clipMaskState);
  65.     if (clipMaskState == kQ3XClipMaskNotExposed) {
  66.         return (kQ3Success);
  67.     }
  68.  
  69.     /*
  70.      *  Lazy-evaluate the various transforms for the pipeline
  71.      */
  72.     if (SR_UpdatePipeline(srPrivate) == kQ3Failure) {
  73.         return (kQ3Failure);
  74.     }
  75.  
  76.     /*
  77.      *  Amazingly enough, triangles have three vertices :-)
  78.      */
  79.     numVertices = 3;
  80.                 
  81.     /*
  82.      *  Highlight state and  color are from the view, unless
  83.      *  overridden by the triangleAttributeSet
  84.      */
  85.     highlightState     = srPrivate->viewHighlightState;
  86.     color             = srPrivate->viewDiffuseColor;
  87.  
  88.     /*
  89.      *  Check if we have a triangle attribute set.
  90.      *  If so, then see if we can get a color and highlight state
  91.      *  out of it. 
  92.      */
  93.     if (triangleData->triangleAttributeSet != NULL) {
  94.         TQ3XAttributeMask    attributeMask;
  95.         
  96.         attributeMask = Q3XAttributeSet_GetMask(triangleData->triangleAttributeSet);
  97.         
  98.         if (attributeMask & kQ3XAttributeMaskDiffuseColor) {
  99.             Q3AttributeSet_Get(
  100.                 triangleData->triangleAttributeSet,
  101.                 kQ3AttributeTypeDiffuseColor,
  102.                 &color);
  103.         }
  104.  
  105.         if (attributeMask & kQ3XAttributeMaskHighlightState) {
  106.             Q3AttributeSet_Get(
  107.                 triangleData->triangleAttributeSet, 
  108.                 kQ3AttributeTypeHighlightState, 
  109.                 &highlightState);
  110.         }
  111.     }
  112.  
  113.     /*
  114.      *  If we're highlighting, then see if we can get a highlight color
  115.      *  out of the view's attribute set. Use that as the color, if it's there.
  116.      */
  117.     if ((highlightState == kQ3True) &&
  118.         (srPrivate->viewHighlightAttributeSet != NULL)) {
  119.         TQ3XAttributeMask    attributeMask;
  120.         
  121.         attributeMask = Q3XAttributeSet_GetMask(
  122.                             srPrivate->viewHighlightAttributeSet);
  123.                             
  124.         if (attributeMask & kQ3XAttributeMaskDiffuseColor) {
  125.             Q3AttributeSet_Get( 
  126.                 srPrivate->viewHighlightAttributeSet, 
  127.                 kQ3AttributeTypeDiffuseColor, 
  128.                 &color);
  129.         }
  130.     }
  131.     
  132.     /*
  133.      *  Get the normal for the triangle
  134.      */
  135.     SRTriangle_GetNormal(
  136.         (TQ3TriangleData *)triangleData, 
  137.         &normal);
  138.     
  139.     switch (srPrivate->viewFillStyle) {
  140.         case kQ3FillStyleFilled:    
  141.         case kQ3FillStyleEdges: {
  142.             if (SR_LinePipe(
  143.                     srPrivate, 
  144.                     (TQ3Point3D *)triangleData->vertices, 
  145.                     numVertices, 
  146.                     sizeof(TQ3Vertex3D),
  147.                     &color,
  148.                     &normal,
  149.                     DO_POLYGON) == kQ3Failure) {
  150.                 return (kQ3Failure);
  151.             }
  152.             break;
  153.         }
  154.         case kQ3FillStylePoints: {
  155.             if (SR_PointPipe(
  156.                     srPrivate, 
  157.                      (TQ3Point3D *)triangleData->vertices, 
  158.                     numVertices, 
  159.                     sizeof(TQ3Vertex3D),
  160.                     &color,
  161.                     &normal,
  162.                     DO_POLYGON) == kQ3Failure) {
  163.                 return (kQ3Failure);
  164.             }
  165.             break;
  166.         }
  167.         default: {
  168.             return (kQ3Failure);
  169.             break;
  170.         }
  171.     }
  172.  
  173.     return (kQ3Success);
  174. }
  175.